﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary;

namespace Program
{
    public partial class AddPatient : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void OpretBtn_Click(object sender, EventArgs e)
        {
            string cpr = this.TxtCpr.Text.Trim();
            string name = this.TxtNavn.Text.Trim();
            string adress = this.TxtAdresse.Text.Trim();
            string zip = this.TxtPost.Text.Trim();
            string city = this.TxtBy.Text.Trim();
            string phoneNr = this.TxtTlfNr.Text.Trim();
            string email = this.TxtEmail.Text.Trim();
            string injuryType = this.TxtInjuryT.Text.Trim();

            try
            {
                PatientCollection C = GlobalData.Core_.Patientcollection;
                Patient p = C.CreatePatient(cpr, name, adress, zip, city, phoneNr, email, injuryType);
                this.TxtStatus.Text += p.ToString()
                                            + Environment.NewLine;
            }
            catch (Exception except)
            {
                this.TxtStatus.Text = "Patient oprettet.";
                                               
            }
            string filename = System.Web.Hosting.HostingEnvironment.MapPath("/Core.xml");
            GlobalData.SaveCore(filename);

            System.IO.FileStream inStream = new System.IO.FileStream(filename, System.IO.FileMode.Open);
            GlobalData.LoadCore(inStream);
            inStream.Close();


            
        }
        

        protected void TxtCpr_TextChanged(object sender, EventArgs e)
        {

        }

        protected void TxtStatus_TextChanged(object sender, EventArgs e)
        {

        }
    }
}